<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var j=2;
        function doAdd(){

            var tr=document.createElement("tr");//创建tr元素
            /*var td1=document.createElement("td");
            td1.innerHTML=i;
            var td2=document.createElement("td");
            td2.innerHTML="tom"+i;
            var td3=document.createElement("td");
            td3.innerHTML=i;
            var td4=document.createElement("td");
            td4.innerHTML="南京"+i;
            tr.appendChild(td1);
            tr.appendChild(td2);
            tr.appendChild(td3);
            tr.appendChild(td4);*/

            var arrs=[j,"tom"+j,j,"南京"+j];
            //循环创建4列
            for(var i=0;i<4;i++){
                var td=document.createElement("td");
                td.innerHTML=arrs[i];
                tr.appendChild(td);//向tr中添加td元素
            }
            var tb=document.querySelector("tbody");
            tb.appendChild(tr);
            j++;
        }
    </script>
</head>
<body>
<input type="button" value="添加一行"  onclick="doAdd()">
    <table border="1px" width="800">
        <thead>
            <tr>
                <th>编号</th>
                <th>姓名</th>
                <th>年龄</th>
                <th>地址</th>
            </tr>
        </thead>
        <tbody align="center">
            <tr>
                <td>1</td>
                <td>tom1</td>
                <td>1</td>
                <td>南京1</td>
            </tr>
        </tbody>
    </table>
</body>
</html>